package com.yzzrjy.controller.mainservlet.user;

import com.yzzrjy.Service.UserService;
import com.yzzrjy.bean.UserBaseBean;
import com.yzzrjy.util.ResponseUtils;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.SQLException;

//获取用户基础信息需要校核token
@WebServlet(name = "GetUserBaseServlet", value = "/getUserBase")
public class GetUserBaseServlet extends HttpServlet {
    private UserService userService = new UserService();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String uid = request.getParameter("uid");
        String token = request.getParameter("token");
        if(uid == null || token == null){
            ResponseUtils.parameterError(response);
            return;
        }

        try {
            //校验token
            if(!userService.checkUserToken(uid, token)){
                ResponseUtils.userSignError(response);
                return;
            }
            UserBaseBean bean = userService.getUserBase(uid);
            if(bean == null){
                ResponseUtils.userNotExist(response);
                return;
            }
            ResponseUtils.success(response, bean);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
